package 剑指offer;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @ClassName _30包含main函数的栈
 * @Description TODO
 * @Author 昝亚杰
 * @Date 2022/2/22 19:55
 * Version 1.0
 **/
public class _30包含min函数的栈 {

}
class MinStack {

    /** initialize your data structure here. */
    Deque stack1,stack2;
    public MinStack() {
        stack1 = new LinkedList<Integer>();
        stack2 = new LinkedList<Integer>();
    }

    public void push(int x) {
        stack1.push(x);
        if(stack2.isEmpty() || x <= (int)stack2.peek()){
            stack2.push(x);
        }
    }

    public void pop() {
        if(stack1.pop().equals(stack2.peek())){
            stack2.pop();
        }
    }

    public int top() {
        return (int)stack1.peek();
    }

    public int min() {
        return (int)stack2.peek();
    }
}
